home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: quick decision: is n a power of 2?
- Date: Sun, 28 Jan 96 01:12:22 GMT
- Organization: none
- Message-ID: <822791542snz@genesis.demon.co.uk>
- References: <Pine.OSF.3.91.960119114608.18779E-100000@io.UWinnipeg.ca> <TANMOY.96Jan21104404@qcd.lanl.gov> <4e6rs0$dvl@ns.RezoNet.NET> <9601251245.AA12220@dxmint.cern.ch>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <9601251245.AA12220@dxmint.cern.ch>
- danpop@mail.cern.ch "Dan Pop" writes:
-
- >The unary minus operator applied to an unsigned integer is always evaluated
- >using two's complement arithmetic, no matter what representation is used
- >by the implementation for signed integers.
-
- Not exactly. Two's complement is a representation for signed integers so
- unsigned arithmetic clearly doesn't use it. However the nice thing about
- 2's complement arithmetic is that in most instances the underlying bit
- manipulations are (or can be for a suitable definition of overflow behaviour)
- the same as those for unsigned arithmetic (so at the archetecture
- level a single form of, e.g. an ADD instruction, can deal with both).
-
- So the expression (-5) and (-5U) are each evaluated by its own set of rules
- but where signed integers are represented in 2's complement the 2 results
- will have the same underlying bit pattern.
-
- >Tanmoy's point was that by restricting the solution to unsigned integers,
- >the representation of signed integers becomes irrelevant.
-
- That's my point too! :-)
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-